#!/bin/sh

#
# Test that simple error conditions are detected
#

. "$(cd "$(dirname "$0")" && pwd)/common.sh"

cat >$CONFIG <<EOF
file-resource test { contents = "Hello!" }
task complete {
    on-resource test { raw_write(1, "cipher=aes-cbc-plain") }
}
EOF

$FWUP_CREATE -c -f "$CONFIG" -o "$FWFILE"
if $FWUP_APPLY -a -d "$IMGFILE" -i "$FWFILE" -t complete; then
    echo "Expecting missing secret to fail"
    exit 1
fi

cat >$CONFIG <<EOF
file-resource test { contents = "Hello!" }
task complete {
    on-resource test { raw_write(1, "secret=123") }
}
EOF

$FWUP_CREATE -c -f "$CONFIG" -o "$FWFILE"
if $FWUP_APPLY -a -d "$IMGFILE" -i "$FWFILE" -t complete; then
    echo "Expecting missing cipher to fail"
    exit 1
fi

cat >$CONFIG <<EOF
file-resource test { contents = "Hello!" }
task complete {
    on-resource test { raw_write(1, "unsupported=1") }
}
EOF

$FWUP_CREATE -c -f "$CONFIG" -o "$FWFILE"
if $FWUP_APPLY -a -d "$IMGFILE" -i "$FWFILE" -t complete; then
    echo "Expecting unsupported parameter to fail"
    exit 1
fi

